package com.tanguy.user.ui.me.activity

import android.text.TextUtils
import android.view.View
import com.jakewharton.rxbinding2.widget.RxTextView
import com.tanguy.user.R
import com.tanguy.user.base.ImmersionTitleActivity
import com.tanguy.user.net.http.HttpManager
import com.tanguy.user.utlis.extend.getEditTextString
import com.tanguy.user.utlis.extend.requestSucceed
import com.tanguy.user.utlis.extend.setText
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/11/14 0014 18:29
 */
class FeedbackActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_feedback
    override fun initView() {
        super.initView()
        title = "意见反馈"
        titleBar.addRightButton("提交", 0, View.OnClickListener {
            submit()
        })
        val subscribe = RxTextView.textChanges(find(R.id.et_content))
                .subscribe {
                    val format = String.format("还可以输入%d个字", 200 - it.length)
                    setText(R.id.tv_hint, format)
                }
        compositeDisposable.add(subscribe)

    }


    private fun submit() {
        val content = getEditTextString(R.id.et_content)
        if (TextUtils.isEmpty(content)) {
            showToast("内容不能为空")
            return
        }

        HttpManager.feedBack(content)
                .requestSucceed(this) {
                    showToast("反馈成功")
                    finish()
                }
    }
}